using System;
using System.Collections.Generic;

namespace Measurements
{   
    public class DistanceUnit : MeasurementUnit
    {
        private class SiDistanceUnit : DistanceUnit
        {
            public SiDistanceUnit(string name, string unit, double factor)
                : base(name, unit, m => m * factor, m => m / factor) { }
        }
        
        public static DistanceUnit Meter = new DistanceUnit("meter", "m", m => m, m => m);
        public static DistanceUnit Centimeter = new SiDistanceUnit("centimeter", "cm", 1e-2);
        public static DistanceUnit Kilometer = new SiDistanceUnit("kilometer", "km", 1e3);
        
        public static DistanceUnit Foot = new DistanceUnit("foot", "ft", m => m / 0.3048, m => 0.3048 * m);
        
        public static IEnumerable<DistanceUnit> Values
        {
            get
            {
                yield return Meter;
                yield return Centimeter;
                yield return Kilometer;
                yield return Foot;
            }
        }
        
        private DistanceUnit(string name, string unit, ToBaseUnitDelegate toBaseUnit, FromBaseUnitDelegate fromBaseUnit)
            : base (name, unit, Meter, toBaseUnit, fromBaseUnit) { }
    }
   
    public class Distance : Measurement<Distance, DistanceUnit> 
    { 
        public override string ToString()
        {
            return ToString("0.000000", DistanceUnit.Meter);
        }
    }
}
